/**
 * The turn class is an information holder that holds the amount of time for a turn
 * and also the Player that is being used in the turn
 *
 * @author Srinidhi Chaganty
 *
 */

/*
 * TURN STARTS
 * CHECKS FOR RANDOM EVENTS
 * STARTS PLAYER ON MAIN SCREEN (MAP)
 * STARTS THE TIMER FOR PLAYER
 * GO TO TOWN BUY/SELL
 * EXITS TOWN
 * PLACE MULE
 * GO TO TOWN
 * GO TO PUB
 * GO TO LAND OFFICE (BUY PROPERTY) <-- extra credit
 * PUB ENDS TURN
 */

public class Turn {
	private static Player p;		//the player for the turn
	private TurnTimer t;			//the timer for the turn
	private RandomEvent r;			//a random event associated with the turn
	private String randomEventText;	//the message for the random event

	/**
	 * constructor for Turn that takes in a player and sets the time to 50s
	 * @param p the Player passed in
	 */
	public Turn(Player p){
		this.setP(p);

		//check for random events
		r = new RandomEvent(p, GameModel.getInstance().getRound().getRoundNum());
		randomEventText = r.getEventText(); //just a message of what happened (or didn't)

		t = new TurnTimer(p.getTurnTime());
	}


	/**
	 * the constructor for Turn that takes in a player and an amount of time
	 * @param p Player passed in
	 * @param time the amount of time for the turn
	 */
	public Turn(Player p, int time){
		this.setP(p);
		this.setT(new TurnTimer(time));
	}

	/**
	 * Sets the time to the value passed in
	 * @param seconds the new amount of time
	 */
	public void setTime(int seconds){
		this.setT(new TurnTimer(seconds));
	}

	/**
	 * returns the Player used in the turn
	 * @return Player the player used
	 */
	public Player getP() {
		return p;
	}

	/**
	 * changes the Player used in the turn
	 * @param p the new Player
	 */
	public void setP(Player p) {
		this.p = p;
	}

	/**
	 * return the TurnTimer used in the turn
	 * @return TurnTimer the timer used
	 */
	public TurnTimer getT() {
		return t;
	}

	/**
	 * changes the TurnTimer used in the turn
	 * @param t the new timer
	 */
	public void setT(TurnTimer t) {
		this.t = t;
	}

	/**
	 * The player visits the pub and gambles using the rest of the time remaining
	 * in their turn.
	 */
	public void visitPub() {
		Pub pub = new Pub();
		pub.pubMoney(p);
		t.setTurnEnded(true);
	}
	
	/**
	 * gets the text of the random event that occured
	 * @return the text from the random event
	 */
	public String getRandomEventText(){
		return randomEventText;
	}
}
